package c05_set_hashset;

import java.util.HashSet;

public class Test {
    public static void main(String[] args) {
        //1.创建HashSet集合
        HashSet<Cat> cats = new HashSet<>();
        //2.添加小猫元素
        Cat cat1=new Cat("小花", 2);
        Cat cat2=new Cat("小花", 3);

        System.out.println(cats.add(cat1));
        System.out.println(cats.add(cat2));
        System.out.println("equals:"+cat1.equals(cat2));

        System.out.println(cat1.hashCode()%16);
        System.out.println(cat2.hashCode()%16);

        cats.add(cat1);
        cats.add(cat2);
        //3.遍历集合
        for (Cat cat : cats) {
            System.out.println(cat);
        }
        System.out.println("-----------------");
        cats.forEach(System.out::println);

    }
}
